package com.tanhua.server.contoller;


import com.tan.model.vo.PageResult;
import com.tanhua.server.service.SmallVideosService;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Map;

@RestController
@RequestMapping("/smallVideos")
public class SmallVideoController {

     @Autowired
    private SmallVideosService videosService;
    @PostMapping
    public ResponseEntity saveVideo(MultipartFile videoThumbnail, MultipartFile videoFile) throws IOException {
        videosService.saveVideo(videoThumbnail,videoFile);
        return ResponseEntity.ok(null);
    }
    /**
     * 视频列表
     */
    @GetMapping
    public ResponseEntity queryVideoList(@RequestParam(defaultValue = "1")  Integer page,
                                         @RequestParam(defaultValue = "10") Integer pagesize) {
        PageResult result = videosService.queryVideoList(page, pagesize);
        return ResponseEntity.ok(result);
    }
    @PostMapping("/{id}/like")
    public ResponseEntity likeVideo(@PathVariable("id") String id) {
        videosService.likeVideo(id);
        return ResponseEntity.ok(null);
    }
    @PostMapping("/{id}/dislike")
    public ResponseEntity dislikeVideo(@PathVariable("id") String id) {

        videosService.dislikeVideo(id);
        return ResponseEntity.ok(null);
    }
    @PostMapping("/{id}/comments")
    public ResponseEntity queryVideoComments(@PathVariable("id") String videoid, @RequestBody Map map){
        String comment = (String) map.get("comment");
        videosService.saveVideoComments(videoid,comment);

        return ResponseEntity.ok(null);
    }
    @GetMapping("/{id}/comments")
    public ResponseEntity<PageResult> queryVideoComments(@PathVariable("id") String videoObjectid, @RequestParam(defaultValue = "1") Integer page,@RequestParam(defaultValue = "10") Integer pagesize){
       PageResult result = videosService.queryVideoComments(videoObjectid, page, pagesize);
       return ResponseEntity.ok(result);
    }
    @PostMapping("comments/{id}/like")
    public ResponseEntity likeVideoComments(@PathVariable("id") String id){
        videosService.likeVideoComments(id);
        return ResponseEntity.ok(null);

    }
    @PostMapping("comments/{id}/dislike")
    public ResponseEntity dislikeVideoComments(@PathVariable("id") String id){
        videosService.dislikeVideoComments(id);
        return ResponseEntity.ok(null);
    }
    @PostMapping("/{uid}/userFocus")
    public ResponseEntity userFocus(@PathVariable("uid") String userid){
        Long focusid = Long.valueOf(userid);
        videosService.userFocus(focusid);
        return ResponseEntity.ok(null);

    }


    @PostMapping("/{uid}/userUnFocus")
    public ResponseEntity userUnFocus(@PathVariable("uid") String userid){
        Long disfocusid = Long.valueOf(userid);
        videosService.userUnFocus(disfocusid);
        return ResponseEntity.ok(null);
    }

}